package huffmanTree;

import com.cn.stepLock.ExecuteRequest;
import com.cn.stepLock.ObjectStepLock;
import com.cn.stepLock.executeLambda.BiConsumerLambda;
import com.google.common.collect.ImmutableList;

import java.util.List;

/**
 * @author Aaron
 * @desc
 * @createTime 2022-02-25 5:10
 * @since
 */
public class StepLockHuffumanTree<T> extends AlterableHuffmanTree<T> {

    private ObjectStepLock objectStepLock = new ObjectStepLock();

    public StepLockHuffumanTree(List<T> valueList) {
        super(valueList);
    }

    public StepLockHuffumanTree(T value) {
        super(value);
    }

    @Override
    public synchronized void addHuffmanTree(HuffmanTree<T> huffmanTree) {
        ImmutableList<BiConsumerLambda<StepLockHuffumanTree, HuffmanTree>> consumerLambdas = ImmutableList.of(new BiConsumerLambda<StepLockHuffumanTree, HuffmanTree>((x, y) -> x.buildValueFrequencyWhenAddTree(y), this, huffmanTree),
                new BiConsumerLambda<StepLockHuffumanTree, HuffmanTree>((x, y) -> x.buildTree(y), this, huffmanTree),
                new BiConsumerLambda<StepLockHuffumanTree, HuffmanTree>((x, y) -> x.buildCompressDataWhenAddTree(y), this, huffmanTree));
        ExecuteRequest executeRequest  = new ExecuteRequest(consumerLambdas);
        objectStepLock.execute(executeRequest);
//        buildValueFrequencyWhenAddTree(huffmanTree);
//        buildTree(huffmanTree);
//        buildCompressDataWhenAddTree(huffmanTree);
    }
}
